package nz.ac.massey.cs.se400_2013.ass3;

import java.util.Collection;
import java.util.HashSet;

public class ExtendedObjectStore extends SimpleObjectStore implements Visitor {
	
    /**
	 * @author jmcurtis
	 */

	private static ExtendedObjectStore store = new ExtendedObjectStore();
	private static Collection<Paper> paperSet   = new HashSet<Paper>();
	private static Collection<Student> studentSet = new HashSet<Student>();
	private static Collection<Address> addressSet = new HashSet<Address>();
	
	//make it private so that people can't create instances
	private ExtendedObjectStore(){}
	
	//returns the object
	public static ExtendedObjectStore getInstance(){
		return ExtendedObjectStore.store;
	}
	
	// needed as this is in Visitors, just not used
	@Override
	public void visit(Course course) {}
	
	// implements the visitor methods from Visitor
	@Override
	public void visit(Address address) {addressSet.add(address);}
	
	@Override
	public void visit(Student student) {studentSet.add(student);}
	
	@Override
	public void visit(Paper paper) {paperSet.add(paper);}
	
	// return the separate sets of objects
	public Collection<Address> getAddresses(){
		courseWalkThrough();
		return ExtendedObjectStore.addressSet;
	}
	
	public Collection<Student> getStudents(){
		courseWalkThrough();
		return ExtendedObjectStore.studentSet;
	}
	
	public Collection<Paper> getPapers(){
		courseWalkThrough();
		return ExtendedObjectStore.paperSet;
	}
	
	public Collection<Course> getCourses(){
		return SimpleObjectStore.COURSES;
	}
	
	private void courseWalkThrough(){
		for(Course c:SimpleObjectStore.COURSES){
			c.accepts(store);
		}
	}
	
	// prevents cloning of the extended objects that allow cloning
	public Object clone() throws CloneNotSupportedException {
		throw new CloneNotSupportedException();
	}
}
